#include "includes.h"

#ifdef RXDBG
#define USE_UART
#endif	//RXDBG


#ifdef USE_UART

void UartInit(uint8_t brt)
{
#ifndef USE_UART_SHIFT
	P0M0 |= BIT3;						//Set P03 as output
	P0M1 |= BIT4;						//Set P04 pull up
#endif	//USE_UART_SHIFT
#ifdef USE_UART_SHIFT
	PSFT |= 0x20;						//Shift UART to 'RXD(P13)/TXD(P12)'
	P1M0 |= BIT2;						//Set P12 as output
	P1M1 |= BIT3;						//Set P13 pull up
#endif	//USE_UART_SHIFT
	TCKCON &= ~(BIT2|BIT3);	//Timer1 1 prescaled
	PCON |= 0x80;						//Buard rate select
	TH1 = brt;
	TL1 = brt;
	TMOD |= 0x20;
	TCON |= 0x40;
	SCON = 0x50;						//Mode 1 TXRX
#ifdef USE_UART_ISR
	IE0 |= BIT4;
#endif	//USE_UART_ISR
}

void UartDis(void)
{
	SCON = 0x40;
}

void UartTxDat(uint8_t dat)
{
	SBUF = dat;
	while(!(SCON&BIT1));
	SCON &= ~BIT1;
}

void UartTxPtr(uint8_t *ptr, len)
{
	uint8_t i;
	
	for(i=0; i<len; i++)
	{
		UartTxDat(*ptr++);
	}
}

#endif	//__UART_H



